<?php
/**
 * created by zzy
 * date: 2017/10/24 9:28
 */

namespace App\Eloquent\Ygt;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProcessFieldRelation extends DbEloquent{

    use SoftDeletes;
    protected $dates    = ['deleted_at'];
    protected $table    = 'ygt_process_field_relation';

    //
    public static function getFieldListByProcessId( $companyId, $processId )
    {
        $fields         = 'a.title,a.field_type,';
        $where          = [
            'ygt_process_field_relation.process_id'=>$processId,
            'a.company_id'=>$companyId
        ];
        $field_r        = 'ygt_process_field_relation.field_id';
        $join           = [
            ['table'=>'ygt_process_field_company as a', 'field_l'=>'a.field_id', 'field_c'=>'=', 'field_r'=>$field_r]
        ];
        $fields         .= 'ygt_process_field_relation.id as relation_id,';
        $fields         .= 'ygt_process_field_relation.process_id as process_id,';
        $fields         .= 'ygt_process_field_relation.is_must,';
        $fields         .= 'ygt_process_field_relation.orderby';
        $orderby        = ['ygt_process_field_relation.orderby','asc'];
        $result         = self::getList($where,$fields,'','',$orderby,'',$join);
        return $result;
    }
    public static function getFieldInfoById( $companyId, $id )
    {
        $fields         = 'a.title,a.field_type,';
        $where          = [
            'ygt_process_field_relation.id'=>$id,'a.company_id'=>$companyId
        ];
        $field_r        = 'ygt_process_field_relation.field_id';
        $join           = [
            ['table'=>'ygt_process_field_company as a', 'field_l'=>'a.field_id', 'field_c'=>'=', 'field_r'=>$field_r]
        ];
        $fields         .= 'ygt_process_field_relation.id as relation_id,';
        $fields         .= 'ygt_process_field_relation.process_id as process_id,';
        $fields         .= 'ygt_process_field_relation.is_must';
        $orderby        = ['ygt_process_field_relation.orderby','asc'];
        $result         = self::getInfo($where,$fields,$orderby,'',$join);
        return $result;
    }

}
